<?php
namespace App\Http\Controllers\Admin\Member;

use App\Repositories\Admin\StaffRepository;
use App\Utilities\JiugeForm;
use App\Utilities\Upload;
use Illuminate\Http\Request;

class StaffController extends BaseController
{
    /**
     * 员工
     */

    protected $view = 'admin.member.staff.';//视图前缀
    protected $url = 'staff';//路由前缀
    protected $model;
//    protected $formElementArr = [//表单元素
//        //array(表单选项,中文名称,name字段名称,表单提示,js验证规则)
//        array(1,'用户名','name','用户名',1),
//        array(5,'所属父级','pid','父级分类',6),
//    ];
//    protected $fieldShowArr = [
//        'id' => 'ID',
//        'name' => '用户名',
//        'pid' => '所属父级',
//        'createTime' => '创建时间',
//    ];

    public function __construct()
    {
        parent::__construct();
        $this->prefix_url = $this->prefix_url.'/'.$this->url;
        $this->model = new StaffRepository();
        view()->share('model',$this->model);
        view()->share('prefix_url',$this->prefix_url);
//        view()->share('jiugeForm',new JiugeForm($this->prefix_url));
    }

    public function index()
    {
        $models = $this->model->getIndexList();
        return view($this->view.'index',array(
            'datas' => $models,
            'model' => $this->model,
        ));
    }

    public function create(Request $request)
    {
        $uid = isset($request->uid) ? $request->uid : 0;
        return view($this->view.'edit',array(
            'edus' => $this->model->getEdus(),
            'politics' => $this->model->getPolitys(),
            'marrys' => $this->model->getMarrys(),
            'skills' => $this->model->getSkillList(),
            'hobbys' => $this->model->getHobbyList(),
            'uid' => $uid,
        ));
    }

    public function store(Request $request)
    {
        $resData = $this->getData($request);
        $this->model->setAdd($resData);
        return redirect($this->prefix_url);
    }

    public function edit(Request $request,$id)
    {
        $uid = isset($request->uid) ? $request->uid : 0;
        return view($this->view.'edit',array(
            'edus' => $this->model->getEdus(),
            'politics' => $this->model->getPolitys(),
            'marrys' => $this->model->getMarrys(),
            'skills' => $this->model->getSkillList(),
            'hobbys' => $this->model->getHobbyList(),
            'data' => $this->model->getAdminShow($id),
            'uid' => $uid,
        ));
    }

    public function update(Request $request,$id)
    {
        $model = $this->model->getAdminShow($id);
        $resData = $this->getData($request);
        //形象照处理
        if ($model->image && $resData['image']) {
            $imageOld = $model->image;
        }
        if (!$resData['image']) { $resData['image'] = $model->image; }
        //身份证正面处理
        if ($model->sfzzm && $resData['sfzzm']) {
            $sfzzmOld = $model->sfzzm;
        }
        if (!$resData['sfzzm']) { $resData['sfzzm'] = $model->sfzzm; }
        //身份证反面处理
        if ($model->sfzfm && $resData['sfzfm']) {
            $sfzfmOld = $model->sfzfm;
        }
        if (!$resData['sfzfm']) { $resData['sfzfm'] = $model->sfzfm; }
        $this->model->setModify($resData,$id);
        //去除老图片
        if (isset($imageOld) && file_exists(ltrim($imageOld,'/'))) {
            unlink(ltrim($imageOld,'/'));
        }
        if (isset($sfzzmOld) && file_exists(ltrim($sfzzmOld,'/'))) {
            unlink(ltrim($sfzzmOld,'/'));
        }
        if (isset($sfzfmOld) && file_exists(ltrim($sfzfmOld,'/'))) {
            unlink(ltrim($sfzfmOld,'/'));
        }
        return redirect($this->prefix_url);
    }

    public function show($id)
    {
        $model = $this->model->getAdminShow($id);
        return view($this->view.'show',array(
            'data' => $model,
        ));
    }

    /**
     * 数据收集
     */
    public function getData(Request $request)
    {
        $res = array();
        $res['uid'] = $request->uid;
        $res['realname'] = $request->realname;
        $res['cate'] = $request->cate;
        $res['job'] = $request->job;
        $res['sex'] = $request->sex;
        $res['birthday'] = $request->birthday;
        $res['education'] = $request->education;
        $res['weight'] = $request->weight ? $request->weight : 0;
        $res['political_status'] = $request->political_status;
        $res['native_place'] = $request->native_place ?
            $request->native_place : '';
        $res['nationality'] = $request->nationality ?
            $request->nationality : '';
        $res['marriage'] = $request->marriage;
        $res['idcard'] = $request->idcard ? $request->idcard : '';
        $res['house'] = $request->house ? $request->house : '';
        $res['household_address'] = $request->household_address ?
            $request->household_address : '';
        $res['residential_address'] = $request->residential_address ?
            $request->residential_address : '';
        $res['contact_person'] = $request->contact_person ?
            $request->contact_person : '';
        $res['contact_phone'] = $request->contact_phone ?
            $request->contact_phone : '';
        $res['salary'] = $request->salary;
        $res['skill'] = $request->skills ? implode(',',$request->skills) : '';
        $res['hobby'] = $request->hobbys ? implode(',',$request->hobbys) : '';
        $fields = array(
            'uid','realname','cate','job','sex','salary',
        );
        foreach ($fields as $field) {
            if (!$res[$field]) {
                echo "<script>alert('信息(真实姓名/员工类型/岗位/性别/薪资)不全！');history.go(-1);</script>";
            }
        }
        if (isset($request->image)) {
            $resImg = Upload::uploadImg($request,'image');
            if ($resImg['code']!=0) {
                echo "<script>alert('形象照错误！');history.go(-1);</script>";
            }
            $res['image'] = $resImg['filePath'];
        } else {
            $res['image'] = '';
        }
        if (isset($request->sfzzm)) {
            $resSfzzm = Upload::uploadImg($request,'sfzzm');
            if ($resSfzzm['code']!=0) {
                echo "<script>alert('形象照错误！');history.go(-1);</script>";
            }
            $res['sfzzm'] = $resSfzzm['filePath'];
        } else {
            $res['sfzzm'] = '';
        }
        if (isset($request->sfzfm)) {
            $resSfzfm = Upload::uploadImg($request,'sfzfm');
            if ($resSfzfm['code']!=0) {
                echo "<script>alert('形象照错误！');history.go(-1);</script>";
            }
            $res['sfzfm'] = $resSfzfm['filePath'];
        } else {
            $res['sfzfm'] = '';
        }
        return $res;
    }

//    /**
//     * 异步查看
//     */
//    public function getShow(Request $request)
//    {
//        if ($request->ajax()) {
//            $id = $request->id;
//            $model = $this->model->getAdminShow($id);
//            if (!$model) { return array('code'=>'-2','msg'=>'记录不存在！'); }
//            //组织数据
//        }
//        return array('code'=>-1,'msg'=>'操作失败！');
//    }

    public function getModelById($id)
    {
        $model = $this->model->getAdminShow($id);
        if (!$model) {
            echo "<script>alert('记录不存在！');history.go(-1);</script>"; exit;
        }
        return $model;
    }





    /**
     * ------------------------------
     * 更多资料
     * ------------------------------
     */

    /**
     * 更多资料编辑
     */
    public function editOption(Request $request)
    {
        $uid = $request->uid;
        $cate = $request->cate;
        $model = $this->model->getOptionAdminByUid($uid);
        $eduBgs = $model['eduBgs'];
        $workHistorys = $model['workHistorys'];
        $familys = $model['familys'];
        $comments = $model['comments'];
        $willFacs = $model['willFacs'];
        $willComs = $model['willComs'];
        $files = $model['files'];
//        dd($model);
        return view($this->view.'option',array(
            'eduBgs' => $eduBgs,
            'workHistorys' => $workHistorys,
            'familys' => $familys,
            'comments' => $comments,
            'willFacs' => $willFacs,
            'willComs' => $willComs,
            'files' => $files,
            'uid' => $uid,
            'cate' => $cate,
        ));
    }

    /**
     * 异步获取业务类型、员工技能
     */
    public function getChecks(Request $request)
    {
        if ($request->ajax()) {
            $resChecks = $this->model->getComRadioList();
            return array('code'=>0,'msg'=>'操作成功！','data'=>$resChecks);
        }
        return array('code'=>-1,'msg'=>'操作失败！');
    }

    /**
     * 异步获取工厂求职意向
     */
    public function getFacWills(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $model = $this->model->getOptionAdminByUid($uid);
            $fabrics = $model['willFacs']['fabricType'];
            $techs = $model['willFacs']['techLevel'];
            $skills = $model['willFacs']['skill'];
            $resFacWills = $this->model->getOptionFacWills();
            $resFabrics = $resFacWills['fabrics'];
            $resTechs = $resFacWills['techs'];
            $resSkills = $resFacWills['skills'];
            $fabricHtml = '';
            $techHtml = '';
            $skillHtml = '';
            $fabricIds = array();
            $skillIds = array();
            if ($fabrics) {
                foreach ($fabrics as $fabric) {
                    $fabricIds[] = $fabric['id'];
                }
            }
            if ($skills) {
                foreach ($skills as $skill) {
                    $skillIds[] = $skill['id'];
                }
            }
//            return array('code'=>-1,'data'=>[$resTechs,$techs]);
            foreach ($resFabrics as $key => $resFabric) {
                $fabricHtml .= '<label>';
                $fabricHtml .= '<input type="checkbox" ';
                $fabricHtml .= 'value="'.$key.'" style="width:20px;" ';
                if (in_array($key,$fabricIds)) {
                    $fabricHtml .= 'checked';
                }
                $fabricHtml .= ' onclick="setFabric('.$key.')" ';
                $fabricHtml .= '> ';
                $fabricHtml .= $resFabric;
                $fabricHtml .= '</label> &nbsp; &nbsp;';
                $fabricHtml .= '<input type="hidden" id="fabricId'.$key.'" value="0">';
            }
            $fabricHtml .= '<input type="hidden" id="fabricCount" value="'.count($resFabrics).'">';
            $techHtml .= '<select id="techSel" style="width:100%">';
            foreach ($resTechs as $key => $resTech) {
                $techHtml .= '<option value="'.$key.'" ';
                if ($techs && $techs['id']==$key) {
                    $techHtml .= 'selected';
                }
                $techHtml .= '>';
                $techHtml .= $resTech;
                $techHtml .= '</option>';
            }
            $techHtml .= '</select>';
            foreach ($resSkills as $key => $resSkill) {
                $skillHtml .= '<label>';
                $skillHtml .= '<input type="checkbox" ';
                $skillHtml .= 'value="'.$key.'" style="width:20px;" ';
                if (in_array($key,$skillIds)) {
                    $skillHtml .= 'checked';
                }
                $skillHtml .= ' onclick="setSkill('.$key.')" ';
                $skillHtml .= '> ';
                $skillHtml .= $resSkill;
                $skillHtml .= '</label> &nbsp; &nbsp;';
                $skillHtml .= '<input type="hidden" id="skillId'.$key.'" value="0">';
            }
            $skillHtml .= '<input type="hidden" id="skillCount" value="'.count($resSkills).'">';
            $dataArr = array(
                'fabricStr' => $fabricHtml,
                'techStr' => $techHtml,
                'skillStr' => $skillHtml,
            );
            return array('code'=>0,'msg'=>'操作成功！','data'=>$dataArr);
        }
        return array('code'=>-1,'msg'=>'操作失败！');
    }

    /**
     * 异步获取公司求职意向
     */
    public function getComWills(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $model = $this->model->getOptionAdminByUid($uid);
            $addresss = $model['willComs']['addresss'];
            $jobModule = $model['willComs']['jobModule'];
            $job = $model['willComs']['job'];
            $salary = $model['willComs']['salary'];
            $workType = $model['willComs']['workType'];
            $industry = $model['willComs']['industry'];
            $jobTime = $model['willComs']['jobTime'];
            $tags = $model['willComs']['tags'];
            $provices = $this->model->getCitys();
            $addressHtml = '';
            $moduleHtml = '';
            $jobHtml = '';
            $salaryHtml = '';
            $workHtml = '';
            $industryHtml = '';
            $jobTimeHtml = '';
            $tagHtml = '';
            $addressHtml .= '<select id="provice" onchange="getCityList(this.value)">';
            foreach ($provices as $provice) {
                $addressHtml .= '<option value="'.$provice['id'].'"';
                if ($addresss['provice']['id']==$provice['id']) {
                    $addressHtml .= ' selected';
                }
                $addressHtml .= ' >';
                $addressHtml .= $provice['name'];
                $addressHtml .= '</option>';
            }
            $addressHtml .= '</select>';
            $addressHtml .= '<select id="city" onchange="getAreaList(this.value)">';
            $addressHtml .= '<option>选择</option>';
            $addressHtml .= '</select>';
            $addressHtml .= '<select id="area">';
            $addressHtml .= '<option>选择</option>';
            $addressHtml .= '</select>';
            $moduleHtml .= '<input type="text" id="module" placeholder="输入职能" value="'.$jobModule.'">';
            $jobHtml .= '<input type="text" id="job" placeholder="输入职位" value="'.$job.'">';
            $salaryHtml .= '<input type="text" id="salary" placeholder="输入薪资" value="'.$salary.'">';
            $workHtml .= '<input type="text" id="work" placeholder="输入工作类型" value="'.$workType.'">';
            $industryHtml .= '<input type="text" id="industry" placeholder="输入所属行业" value="'.$industry.'">';
            $jobTimeHtml .= '<input type="text" id="jobTime" placeholder="输入到岗时间，如：2019-01-01" value="'.$jobTime.'">';
            if ($tags) {
                $tagStr = implode('，',$tags);
                $tagHtml .= '<input type="text" id="tag" placeholder="输入个人标签，中文逗号隔开"  value="'.$tagStr.'">';
            } else {
                $tagHtml .= '<input type="text" id="tag" placeholder="输入个人标签，中文逗号隔开" >';
            }
            $dataArr = array(
                'addressHtml' => $addressHtml,
                'moduleHtml' => $moduleHtml,
                'jobHtml' => $jobHtml,
                'salaryHtml' => $salaryHtml,
                'workHtml' => $workHtml,
                'industryHtml' => $industryHtml,
                'jobTimeHtml' => $jobTimeHtml,
                'tagHtml' => $tagHtml,
            );
            return array('code'=>0,'msg'=>'操作成功！','data'=>$dataArr);
        }
        return array('code'=>-1,'msg'=>'操作失败！');
    }

    /**
     * 更多资料，更新教育背景
     */
    public function setOptionEdu(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $oper = $request->oper;
            $key = $request->key;
            $eduBgStart = $request->eduBgStart;
            $eduBgEnd = $request->eduBgEnd;
            $eduBgSchool = $request->eduBgSchool;
            $eduBgMajor = $request->eduBgMajor;
            $eduBgAward = $request->eduBgAward;
            $model = $this->model->getOptionAdminByUid($uid);
            if (!$model['eduBgs'] && $oper=='add') {
                //return array('code'=>-2, 'msg'=>'没有记录！');
                //没有记录，去创建
//                $resOption = $this->model->getOptionInit();
                $eduBgs = array(
                    'eduBgStart' => array('',$eduBgStart),
                    'eduBgEnd' => array('',$eduBgEnd),
                    'eduBgSchool' => array('',$eduBgSchool),
                    'eduBgMajor' => array('',$eduBgMajor),
                    'eduBgAward' => array('',$eduBgAward),
                    'eduBgCount' => 1,
                );
                $model['eduBgs'] = $eduBgs;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'新增成功！','data'=>$lastId);
            } else if ($model['eduBgs'] && $oper=='add') {
                //有记录，再增加
                $model['eduBgs']['eduBgStart'][] = $eduBgStart;
                $model['eduBgs']['eduBgEnd'][] = $eduBgEnd;
                $model['eduBgs']['eduBgSchool'][] = $eduBgSchool;
                $model['eduBgs']['eduBgMajor'][] = $eduBgMajor;
                $model['eduBgs']['eduBgAward'][] = $eduBgAward;
                $model['eduBgs']['eduBgCount'] ++;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'增加成功！','data'=>$lastId);
            } else if ($model['eduBgs'] && $oper=='modify') {
                //有记录，修改
                $model['eduBgs']['eduBgStart'][$key] = $eduBgStart;
                $model['eduBgs']['eduBgEnd'][$key] = $eduBgEnd;
                $model['eduBgs']['eduBgSchool'][$key] = $eduBgSchool;
                $model['eduBgs']['eduBgMajor'][$key] = $eduBgMajor;
                $model['eduBgs']['eduBgAward'][$key] = $eduBgAward;
//                return array('code'=>-1,'data'=>$model);
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'修改成功！','data'=>$lastId);
            }
        }
        return array('code'=>-1, 'msg'=>'操作失败！');
    }

    /**
     * 更多资料，更新工作经历
     */
    public function setOptionWork(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $oper = $request->oper;
            $key = $request->key;
            $workStart = $request->workStart;
            $workEnd = $request->workEnd;
            $workComName = $request->workComName;
            $workJob = $request->workJob;
            $workLeave = $request->workLeave;
            $model = $this->model->getOptionAdminByUid($uid);
//            return array('code'=>-1,'data'=>$model);
            if (!$model['workHistorys'] && $oper=='add') {
                //没有记录，去创建
//                $resOption = $this->model->getOptionInit();
                $workHistorys = array(
                    'workStart' => array('',$workStart),
                    'workEnd' => array('',$workEnd),
                    'workComName' => array('',$workComName),
                    'workJob' => array('',$workJob),
                    'workLeave' => array('',$workLeave),
                    'workCount' => 1,
                );
                $model['workHistorys'] = $workHistorys;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'新增成功！','data'=>$lastId);
            } else if ($model['workHistorys'] && $oper=='add') {
                //有记录，再增加
                $model['workHistorys']['workStart'][] = $workStart;
                $model['workHistorys']['workEnd'][] = $workEnd;
                $model['workHistorys']['workComName'][] = $workComName;
                $model['workHistorys']['workJob'][] = $workJob;
                $model['workHistorys']['workLeave'][] = $workLeave;
                $model['workHistorys']['workCount'] ++;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'增加成功！','data'=>$lastId);
            } else if ($model['workHistorys'] && $oper=='modify') {
                //有记录，修改
                $model['workHistorys']['workStart'][$key] = $workStart;
                $model['workHistorys']['workEnd'][$key] = $workEnd;
                $model['workHistorys']['workComName'][$key] = $workComName;
                $model['workHistorys']['workJob'][$key] = $workJob;
                $model['workHistorys']['workLeave'][$key] = $workLeave;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'修改成功！','data'=>$lastId);
            }
        }
        return array('code'=>-1, 'msg'=>'操作失败！');
    }

    /**
     * 更多资料，更新家庭成员
     */
    public function setOptionFamily(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $oper = $request->oper;
            $key = $request->key;
            $familyName = $request->familyName;
            $familyCall = $request->familyCall;
            $familyCom = $request->familyCom;
            $familyContact = $request->familyContact;
            $model = $this->model->getOptionAdminByUid($uid);
            if (!$model['familys'] && $oper=='add') {
                //没有记录，去创建
//                $resOption = $this->model->getOptionInit();
                $familys = array(
                    'familyName' => array('',$familyName),
                    'familyCall' => array('',$familyCall),
                    'familyCom' => array('',$familyCom),
                    'familyContact' => array('',$familyContact),
                    'familyCount' => 1,
                );
                $model['familys'] = $familys;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'新增成功！','data'=>$lastId);
            } else if ($model['familys'] && $oper=='add') {
                //有记录，再增加
                $model['familys']['familyName'][] = $familyName;
                $model['familys']['familyCall'][] = $familyCall;
                $model['familys']['familyCom'][] = $familyCom;
                $model['familys']['familyContact'][] = $familyContact;
                $model['familys']['familyCount'] ++;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'增加成功！','data'=>$lastId);
            } else if ($model['familys'] && $oper=='modify') {
                //有记录，修改
                $model['familys']['familyName'][$key] = $familyName;
                $model['familys']['familyCall'][$key] = $familyCall;
                $model['familys']['familyCom'][$key] = $familyCom;
                $model['familys']['familyContact'][$key] = $familyContact;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'修改成功！','data'=>$lastId);
            }
        }
        return array('code'=>-1, 'msg'=>'操作失败！');
    }

    /**
     * 更多资料，更新个人评价
     */
    public function setOptionComment(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $oper = $request->oper;
            $key = $request->key;
            $comFeature = $request->comFeature;
            $comSkill = $request->comSkill;
            $comHobby = $request->comHobby;
            $comExpect = $request->comExpect;
            $businessRadioInput = $request->businessRadioInput;
            $skillRadioInput = $request->skillRadioInput;
            $model = $this->model->getOptionAdminByUid($uid);
            if ($oper=='add') {
                //没有记录，去创建
                $resOption = $this->model->getOptionInit();
                $comments = array(
                    'comFeature' => $comFeature,
                    'comSkill' => $comSkill,
                    'comHobby' => $comHobby,
                    'comExpect' => $comExpect,
                    'businessRadioInput' => $businessRadioInput,
                    'skillRadioInput' => $skillRadioInput,
                );
                $resOption['comments'] = $comments;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$resOption);
                return array('code'=>0,'msg'=>'新增成功！','data'=>$lastId);
            } else if ($model && $oper=='modify') {
                //有记录，修改
                $model['comments']['comFeature'] = $comFeature;
                $model['comments']['comSkill'] = $comSkill;
                $model['comments']['comExpect'] = $comExpect;
                $model['comments']['businessRadioInput'] = $businessRadioInput;
                $model['comments']['skillRadioInput'] = $skillRadioInput;
                $lastId = $this->model
                    ->setOptionAdminByUid($uid,$model);
                return array('code'=>0,'msg'=>'修改成功！','data'=>$lastId);
            }
        }
        return array('code'=>-1, 'msg'=>'操作失败！');
    }

    /**
     * 更多资料，更新工厂意向
     */
    public function setOptionFacWill(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $fabrics = $request->fabrics;
            $techSel = $request->techSel;
            $skills = $request->skills;
            unset($fabrics[0]); unset($skills[0]);
            $resFacWills = $this->model->getOptionFacWills();
            $model = $this->model->getOptionAdminByUid($uid);
//            return array('code'=>-1,'data'=>[$resFacWills,$fabrics,$techSel]);
            $resFabrics = array();
            foreach ($fabrics as $key => $fabric) {
                $resFabrics[] = array(
                    'id' => $fabric,
                    'name' => $resFacWills['fabrics'][$key],
                );
            }
            $resTechs = array(
                'id' => $techSel,
                'name' => $resFacWills['techs'][$techSel],
            );
            $resSkills = array();
            foreach ($skills as $key => $skill) {
                $resSkills[] = array(
                    'id' => $skill,
                    'name' => $resFacWills['skills'][$key],
                );
            }
            $facWills = array(
                'fabricType' => $resFabrics,
                'techLevel' => $resTechs,
                'skill' => $resSkills,
            );
            $model['willFacs'] = $facWills;
            $lastId = $this->model
                ->setOptionAdminByUid($uid,$model);
            return array('code'=>0,'msg'=>'更新成功！','data'=>$lastId);
        }
        return array('code'=>-1, 'msg'=>'操作失败！');
    }

    /**
     * 更多资料，更新公司意向
     */
    public function setOptionComWill(Request $request)
    {
        if ($request->ajax()) {
            $uid = $request->uid;
            $area = $request->area;
            $module = $request->module;
            $job = $request->job;
            $salary = $request->salary;
            $work = $request->work;
            $industry = $request->industry;
            $jobTime = $request->jobTime;
            $tag = $request->tag;
            if (!$area) {
                return array('code'=>-2,'msg'=>'地点错误！');
            }
            if (!preg_match('/\d\d\d\d-\d\d-\d\d/',$jobTime)) {
                return array('code'=>-3,'msg'=>'到岗时间格式错误！');
            }
            if (!$tag) {
                return array('code'=>-3,'msg'=>'标签错误！');
            }
            $parents = $this->model->getCityParent($area);
            $addressStr = $parents['provice']['name'].'，'
                .$parents['city']['name'].'，'.$parents['area']['name'];
            $tags = explode(',',$tag);
            $model = $this->model->getOptionAdminByUid($uid);
            $model['willComs'] = array(
                'address' => $addressStr,
                'jobModule' => $module,
                'job' => $job,
                'salary' => $salary,
                'workType' => $work,
                'industry' => $industry,
                'jobTime' => $jobTime,
                'tags' => $tags,
            );
//            return array('code'-1,'data'=>$model);
            $lastId = $this->model
                ->setOptionAdminByUid($uid,$model);
            return array('code'=>0,'msg'=>'更新成功！');
        }
        return array('code'=>-1, 'msg'=>'操作失败！');
    }

    /**
     * 更新可选项的员工认证
     */
    public function setFile(Request $request)
    {
        $uid = $request->uid;
        $fileId = $request->fileId;
        $fileKey = $request->fileKey;
        $prefix = $request->prefix;
        if (!$fileId || !$fileKey) {
            echo "<script>alert('参数错误！');history.go(-1);</script>"; exit;
        }
        if (!isset($request->fileUrl)) {
            echo "<script>alert('图片没有上传！');history.go(-1);</script>"; exit;
        }
        $resFile = Upload::uploadImg($request,'fileUrl');
        if ($resFile['code']!=0) {
            echo "<script>alert('上传错误！');history.go(-1);</script>"; exit;
        }
        $imgUrl = $resFile['filePath'];
        $model = $this->model->getOptionAdminByUid($uid);
        $model['files'][$fileKey][] = $imgUrl;
        $lastId = $this->model
            ->setOptionAdminByUid($uid,$model);
        return redirect($prefix.'#file');
    }
}